/**
 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
 */
// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作
const install = (Vue, vm) => {

	// 参数配置对象
	const config = vm.vuex_config;

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.api = {
		// 退出登录
		wxLogOut: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/logout', ''),
		map: (url, params = {}) => vm.$jsonp(url, {
			key: "e98e7d88b5571dffdd9b19d9b9bba61d",
			...params
		}),
		upload: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/oss/upload', {
			['content-type']: 'multipart/form-data',
			...params
		}),
		// 获取用户信息
		getUserMes: (params = {}) => vm.$u.get(config.adminPath + '/applet/my/info', params),
		getWxQrcode: (params = {}) => vm.$u.get(config.adminPath + '/h5/qrcode/wechat', params),
		// 更新用户信息
		updateUserMes: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/my/info', params),
		updateRunnerMes: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/my/runner/info', params),
		// 个人中心资料
		getUserInfo: (params = {}) => vm.$u.get(config.adminPath + '/applet/my/index', params),
		getRunnerUserInfo: (params = {}) => vm.$u.get(config.adminPath + '/applet/my/runner', params),
		// 获取个人中心资料
		getRunnerInfo: (params = {}) => vm.$u.get(config.adminPath + '/applet/my/runner/info', params),
		// 获取基本配置
		getClientConfig: (params = {}) => vm.$u.get(config.adminPath + '/applet/config', params),
		// 获取优惠券
		getCoupon: (params = {}) => vm.$u.get(config.adminPath + '/applet/my/coupon', params),

		// 提交实名申请
		submitRealName: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runner/validate/card', params),
		submitRealNameApply: (params = {}) => vm.$u.put(config.adminPath + `/applet/runner/validate/${params.schoolId}`, params),
		// 获取优惠券
		queryRealNameProcess: (params = {}) => vm.$u.get(config.adminPath + '/applet/runner/Validate/index', params),

		/****************************** 统计 **************************/
		queryStatistics: (params = {}) => vm.$u.get(config.adminPath + '/applet/statistics', params),
		queryStatisticsByState: ({ type, state, ...params } = {}) => vm.$u.get(config.adminPath + `/applet/statistics/order/${type}/${state}`, params),

		/****************************** 接单大厅 **************************/
		queryHallHeadDataSource: (params = {}) => vm.$u.get(config.adminPath + '/applet/runner/index/head', params),
		queryHallTaskList: (params = {}) => vm.$u.get(config.adminPath + '/applet/runner/index', params),
		queryHallTaskListBySite: ({ type, siteId, ...params }) => vm.$u.get(config.adminPath + `/applet/runner/index/${type}/${siteId}`, params),
		invokeSyncLocation: ({ lat, lon, ...params }) => vm.$u.put(config.adminPath + `/applet/runner/gps/${lat}/${lon}`, params),
		// 切换在线状态
		invokeModifyStatus: ({ state, ...params }) => vm.$u.put(config.adminPath + `/applet/runner/index/head/state/${state}`, params),
		// 抢单
		invokeHallTaskBySite: ({ no, siteId, ...params }) => vm.$u.put(config.adminPath + `/applet/runner/index/get/${no}/${siteId}`, params),
		// 校验收货码
		invokeHallTaskValidCode: ({ no, code, ...params }) => vm.$u.get(config.adminPath + `/applet/runner/index/code/${no}/${code}`, params),
		// 确认送达
		invokeHallTaskConfirmReceived: ({ no, ...params }) => vm.$u.postJson(config.adminPath + `/applet/runner/index/arrive/${no}`, params),
		// 评分
		invokeHallTaskScore: ({ no, score, ...params }) => vm.$u.put(config.adminPath + `/applet/runOrder/my/info/${no}/score/${score}`, params),

		// 我的订单详情
		queryOrderDetail: ({ tradeNo, ...params }) => vm.$u.get(config.adminPath + `/applet/runOrder/my/info/${tradeNo}`, params),
		// 确认送达
		invokeOrderConfirm: ({ tradeNo, flg, ...params }) => vm.$u.postJson(config.adminPath + `/applet/runOrder/my/info/${tradeNo}/arrive/${flg}`, params),
		// 取消订单
		invokeCancelOrder: ({ tradeNo, ...params }) => vm.$u.put(config.adminPath + `/applet/runOrder/cancel/${tradeNo}`, params),
		// 修改地址
		getModifyOrderAddress: ({ tradeNo, ...params }) => vm.$u.get(config.adminPath + `/applet/runOrder/my/info/${tradeNo}/address`, params),
		invokeModifyOrderAddress: ({ tradeNo, ...params }) => vm.$u.postJson(config.adminPath + `/applet/runOrder/my/info/${tradeNo}/address`, params),

		// 钱包余额
		queryWallet: (params = {}) => vm.$u.get(config.adminPath + '/applet/wallet', params),
		queryWalletType: (params = {}) => vm.$u.get(config.adminPath + '/applet/wallet/out/init', params),
		queryWalletList: (params = {}) => vm.$u.get(config.adminPath + '/applet/wallet/detail', params),
		invokeWalletOperator: ({ type, ...params } = {}) => vm.$u.postJson(config.adminPath + `/applet/wallet/out/${type}`, params),

		// 消息中心
		getMessageList: (params = {}) => vm.$u.get(config.adminPath + `/applet/ws/page/my/${params.type || 'APPLET'}`, params),
		invokeMessageStatus: (params = {}) => vm.$u.put(config.adminPath + `/applet/ws/read/${params.id}`, params),
		invokeOneKeyReadMessage: (params = {}) => vm.$u.put(config.adminPath + `/applet/ws/read/all/${params.type || 'APPLET'}`, params),
		invokeDeleteMessage: (params = {}) => vm.$u.put(config.adminPath + `/applet/ws/del/${params.id}`, params),
		invokeReadMessage: (params = {}) => vm.$u.put(config.adminPath + `/applet/ws/read/${params.id}`, params),

		// 微信登录
		wxLogin: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/login/wx', params),
		wxBind: (params = {}) => vm.$u.put(config.adminPath + `/applet/wx/${params.code}`, params),
		sendReplacePhoneCode: (params = {}) => vm.$u.get(config.adminPath + `/applet/tel/reset/${params.tel}`, params),
		sendReplacePhoneCodeLast: (params = {}) => vm.$u.put(config.adminPath + `/applet/tel/reset/${params.tel}/${params.code}`, params),
		// 注册+登录
		registerLogin: (params = {}) => vm.$u.post(config.adminPath + `/applet/register/${params.phoneNo}/code/${params.code}`, params),
		// 获取注册验证码
		getRegisterCode: (params = {}) => vm.$u.get(config.adminPath + `/applet/sms/register/${params.phoneNo}`, params),
		// 注册设置密码
		registerSetPassword: (params = {}) => vm.$u.postJson(config.adminPath + `/applet/password`, params),
		// 获取忘记密码验证码
		getForgetCode: (params = {}) => vm.$u.get(config.adminPath + `/applet/sms/password/reset/${params.phoneNo}`, params),
		// 忘记密码 重置密码
		resetPassword: (phoneNo, params = {}) => vm.$u.postJson(config.adminPath + `/applet/password/reset/${phoneNo}`, params),
		// 账号密码登录
		login: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/login/password', params),
		// 首页获取初始数据（包含能选择的站点）
		getHomeInit: (params = {}) => vm.$u.get(config.adminPath + '/applet/runOrder/add/init', params),
		// 首页获取校区
		getHomeSchool: (params = {}) => vm.$u.get(config.adminPath + '/applet/runOrder/add/init/school/select', params),
		// 首页选择校区后获取该校区站点
		getHomeSchoolSite: (schoolId, params = {}) => vm.$u.get(config.adminPath + '/applet/runOrder/add/init/site/select/' + schoolId, params),
		// 获取校区下拉列表
		getSchoolList: (params = {}) => vm.$u.get(config.adminPath + '/applet/address/put/select', params),
		// 获取地址簿列表
		getAddressList: (params = {}) => vm.$u.get(config.adminPath + '/applet/address/list/my', params),
		// 删除地址簿
		deleteAddress: (params = {}) => vm.$u.delete(config.adminPath + '/applet/address/' + params.id),
		// 新增和编辑地址簿
		addAddress: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/address/put', params),
		putAddress: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/address/put/' + params.id, params),
		// 货物类型下啦
		getGoodsTypeList: (params = {}) => vm.$u.get(config.adminPath + '/applet/runOrder/goods/type', params),
		// 获取该订单可用优惠券
		getOrderCouponList: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/coupon/list', params),
		// 计算订单价格
		calcPrice: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/price', params),
		// 计费规则
		calcRule: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/price/rule', params),
		// 创建订单并支付
		addOrder: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/add', params),
		addAppOrder: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/add/app', params),
		appOrderPay: (params = {}) => vm.$u.get(config.adminPath + `/applet/runOrder/transactions/${params.orderId}`, params),
		// 订单号支付
		orderNoPay: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/unifiedorder', params),
		// 用户订单
		cuserOrderList: (params = {}) => vm.$u.postJson(config.adminPath + '/applet/runOrder/my', params),
		// 用户订单详情
		cuserOrderDetail: (params = {}) => vm.$u.get(config.adminPath + `/applet/runOrder/my/info/${params.tradeNo}`, params),
		// 用户订单取消
		cuserOrderCancel: (params = {}) => vm.$u.put(config.adminPath + `/applet/runOrder/cancel/${params.tradeNo}`, params),
		feedback: (params = {}) => vm.$u.postJson(config.adminPath + `/applet/my/feedback`, params),
		getCodeInShare: (params = {}) => vm.$u.get(config.adminPath + `/h5/code/${params.tel}`, params),
		getCodeInRegister: ({ tel, ...params } = {}) => vm.$u.postJson(config.adminPath + `/h5/visit/${tel}`, params),
		getH5Config: (params = {}) => vm.$u.get(config.adminPath + `/h5`, params),
		getOrderCount: (params = {}) => vm.$u.postJson(config.adminPath + `/applet/runOrder/my/count`, params),
		invokeProxyLogin: (params = {}) => vm.$u.put(config.adminPath + `/applet/dls`, params, {
			"content-type": "application/json"
		}),
		invokeProxyLoginCode: ({ tel, ...params } = {}) => vm.$u.get(config.adminPath + `/applet/dls/${tel}`, params),

	};

}

export default {
	install
}